#ifndef QTRANSLATETREEWIDGET_H
#define QTRANSLATETREEWIDGET_H

#include <QTreeWidget>
#include <QItemDelegate>
#include <QList>
#include <QMap>
#include <QVector>
#include <QPair>

namespace SHAREDLIB
{
    class tagLanguageItem;
}

class QTranslateTreeWidget;
class QTranslateDelegate: public QItemDelegate
{
    Q_OBJECT
public :
    QTranslateDelegate(QTranslateTreeWidget* parent):m_listView(parent){}
    QWidget* createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const;
    void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const;
    void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const;
    QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const;
    void    setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const;
    void    setEditorData(QWidget *editor, const QModelIndex &index) const;
protected:
    QTranslateTreeWidget   *m_listView;
};

class QTranslateTreeWidget: public QTreeWidget
{
    Q_OBJECT
public:
    QTranslateTreeWidget(QWidget* parent);


    QTreeWidgetItem *indexToItem(const QModelIndex &index) const;

    bool    isGroupItem(QTreeWidgetItem* item)const ;

    void    addTranslateItem(SHAREDLIB::tagLanguageItem* translate);



    void    removeCurrent();

    void    updateAll();

public slots:
    void    cammand_changed();
    void    cammand_add();
    void    cammand_remove();
public slots:
    void    clearAll();
protected:
    void    mousePressEvent(QMouseEvent *event);
    void    drawRow(QPainter *painter, const QStyleOptionViewItem &options, const QModelIndex &index) const;
private:
    friend class QTranslateDelegate;
protected slots:
    void    refresh();
    void    translateChanged(SHAREDLIB::tagLanguageItem *item);
    void    removeTranslate(const QString &id);
protected:
    QList<QTreeWidgetItem*>         m_groups;
    QMap<QString,QTreeWidgetItem*>  m_nameToGroup;
    QMap<SHAREDLIB::tagLanguageItem*,QTreeWidgetItem*>  m_items;
    QVector<QPair<QColor,QColor> >                          m_colors;
    QMap<QObject*,int>              m_languageIndex;
    QIcon                                                   m_expandIcon;
};

#endif // QTRANSLATETREEWIDGET_H
